//
//  SYScrollDetailsViewController.m
//  TermOfSectionB
//
//  Created by 韩震明 on 15/11/29.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "SYScrollDetailsViewController.h"

@interface SYScrollDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain) SYBaseTableView *tableView;
@property(nonatomic, retain) NSMutableArray *topicArr;

@end

@implementation SYScrollDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigation];
    
    [self createTableView];
    
    [self createSVData];
    
}

#pragma mark - TableView Setting

- (void)createTableView
{
    self.tableView = [[SYBaseTableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain superView:self.view delegate:self rowHeight:150 separatorStyle:NO showsVerticalScrollIndicator:NO showsHorizontalScrollIndicator:NO header:nil];
    
    [self.tableView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.tableView registerClass:[SYSpecialTVCell class] forCellReuseIdentifier:@"tableViewReuse"];
}

#pragma mark - TableView Delegate Method

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.topicArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SYSpecialTVCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"tableViewReuse"];
    cell.topicModel = self.topicArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if ([[self.topicArr[indexPath.row] cellType] isEqualToString:@"0"]) {
//        HZMTableDetailsVC *tableVC = [[HZMTableDetailsVC alloc] init];
//        [self.navigationController pushViewController:tableVC animated:YES];
//        tableVC.urlStr = [NSString stringWithFormat:@"http://open3.bantangapp.com/topic/info?app_installtime=1445332782.662591&app_versions=4.2.3&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&id=%@&oauth_token=bf8be334eb1fd06b1bf65f5883dd415a&os_versions=9.1&screensize=1242&statistics_uv=1&track_device_info=iPhone72C1&track_deviceid=2F83AC09-B470-4C43-9DEE-E0FB95B4B438&track_user_id=1457891&v=7", [self.topicArr[indexPath.row] cellId]];
//    } else {
//        HZMTableDetailsType1VC *type = [[HZMTableDetailsType1VC alloc] init];
//        type.strUrl = [NSString stringWithFormat:@"http://open3.bantangapp.com/topic/info?app_installtime=1445332782.662591&app_versions=4.2.3&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&id=%@&oauth_token=bf8be334eb1fd06b1bf65f5883dd415a&os_versions=9.1&screensize=1242&statistics_uv=1&track_device_info=iPhone72C1&track_deviceid=2F83AC09-B470-4C43-9DEE-E0FB95B4B438&track_user_id=1457891&v=7", [self.topicArr[indexPath.row] cellId]];
//        [self.navigationController pushViewController:type animated:YES];
//    }
}

#pragma mark - Navigation Setting

- (void)setNavigation
{
    self.navigationItem.title = self.bannerModel.title;
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(-20, 0, 40, 40);
    [leftButton setImage:[UIImage imageNamed:@"nav_back@2x.png"] forState:UIControlStateNormal];
    [self.view addSubview:leftButton];
    [leftButton addTarget:self action:@selector(leftBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
}

#pragma mark - Navigationbar ButtonAction

- (void)leftBarButtonClick:(UIBarButtonItem *)leftBarButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Create Data

- (void)createSVData
{
    if ([self.bannerModel.bannerType isEqualToString:@"topic_list"]) {
        NSString *strURL = [NSString stringWithFormat:@"http://open3.bantangapp.com/topic/list?app_installtime=1445332782.662591&app_versions=4.2.3&channel_name=appStore&client_id=bt_app_ios&client_secret=9c1e6634ce1c5098e056628cd66a17a5&ids=%@&oauth_token=bf8be334eb1fd06b1bf65f5883dd415a&os_versions=9.1&page=0&pagesize=20&screensize=1242&track_device_info=iPhone72C1&track_deviceid=2F83AC09-B470-4C43-9DEE-E0FB95B4B438&track_user_id=1457891&v=7", [self.bannerModel.extend stringByReplacingOccurrencesOfString:@"," withString:@"%2C"]];
        [AFN GETDataWithURL:strURL block:^(id result) {
            NSDictionary *dic = result;
            self.topicArr = [NSMutableArray array];
            self.topicArr = [SYScrollDetailsModel baseModelByArr:dic[@"data"][@"topic"]];
            [self.tableView reloadData];
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
